<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">退货商品管理</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">退货商品列表</div>
                    <div class="panel-body inner-body">
                        <div class="main-box-search">
                            <form method="get" name="from1"  id="searchForm"  >
                                <div class="search-row">
                                    <input type="hidden" name="" value="">
                                    <div class="col-lg-3 col-md-6" style=" margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" id="orderId" placeholder="请输入订单id">
                                    </div>
                                    <div class="col-lg-3 col-md-6" style=" margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" id="accountId" placeholder="请输入购买者id">
                                    </div>
                                   <div class="col-lg-2 col-md-6" style="margin-bottom:15px; padding-left:0px;">
                                        <select class="form-control" id="status">
                                            <option value="0">全部</option>
                                            <option value="1">申请中</option>
                                            <option value="2">待退货</option>
                                            <option value="3">待退款</option>
                                            <option value="4">退款成功</option>
                                            <option value="5">退款关闭</option>
                                            <option value="6">退款取消</option>
                                        </select>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="ta">
                                <thead>
                                <tr>
                                    <th class="text-center" style="width:5%;">订单编号</th>
                                    <th class="text-center" style="width:24%;">商品名称</th>
                                    <th class="text-center" style="width:6%;">商品id</th>
                                    <th class="text-center" style="width:8%;">退款数量</th>
                                    <th class="text-center" style="width:10%;">购买者id</th>
                                    <th class="text-center" style="width:10%;">购买者昵称</th>
                                    <th class="text-center" style="width:8%;">实付金额</th>
                                    <th class="text-center" style="width:6%">退款进度</th>
                                    <th class="text-center" style="width:12%">退款说明</th>
                                    <th class="text-center" style="width:12%">商户订单号</th>
                                    <th class="text-center" style="width:8%;">操作</th>
                                </tr>
                                </thead>
                                <tbody  id="orderProductRefundList">
                                
                                </tbody>
                            </table>
                        </div>
                        <div class="modal fade" id="modifyModel">
                            <div class="modal-dialog modal-sm">
                                <div class="modal-content message_align">
                                    <div class="modal-header">
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        <h4 class="modal-title">修改金额</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input type="text" id="realPrice" name="realPrice" class="form-control" placeholder="请输入金额"
                                               required>
                                    </div>
                                    <div class="modal-footer">
                                        <input id="url" type="hidden">
                                        <button class="btn btn-default" type="button" data-dismiss="modal">取消</button>
                                        <a class="btn btn-danger" onclick="pro_modify()" data-dismiss="modal">确定</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="text-right">
                            <ul class="pagination" id="pagination">
                                <li><a href="javascript:void(0);" onclick="" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
				                <li><a  href="javascript:void(0);" onclick="" >1</a></li>
				                <li><a href="javascript:void(0);" onclick=""  aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
	var ref = "";
	searchCase(0,1);
	/* ref = setInterval(function(){
		searchCase(0,1);
		},60000); */
	var excelPage = 1;
	$('#searchForm').change(function(e) {
		searchCase(1,1);
	})
	
	//搜索
	function searchCase(flag,page) {
		excelPage = page;
		var status = null;
		var mallUuid = "${searchMallUuid}";
		if(flag == 1){
			status=$("#status option:selected").val();  //获取选中的项
			if(status == 0){
				status = null;
			}
		}
		var enabled = "${enabled}";
		if(enabled == 0){
			mallUuid = "${mallUuid}";
		}
		var orderId = $("#orderId").val();
		var accountId = $("#accountId").val();
		var pageSize= 10;
		
		var baseURL = "${webPath}/orderProductRefund/list";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"orderId": orderId,
	        	"accountId": accountId,
	        	"status": status,
	        	"mallUuid":mallUuid,
	            "page": page,
	            "pageSize": pageSize
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            $("#orderProductRefundList").empty();
	        } else {
	        	$("#orderProductRefundList").empty();
	        	var list = result.body.list;
	        	var count = result.body.count;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	
	        	for(var i=0;i<list.length;i++){
	        		str += '<tr>';
	        		str += '	<td class="text-center">'+list[i].orderId+'</td>';
	        		str += '	<td class="text-center">'+list[i].productName+'</td>';
	        		str += '	<td class="text-center">'+list[i].productId+'</td>';
	        		str += '	<td class="text-center">'+list[i].count+'</td>';
	        		str += '	<td class="text-center">'+list[i].accountId+'</td>';
	        		str += '	<td class="text-center">'+list[i].accountNickName+'</td>';
	        		str += '	<td class="text-center">'+list[i].realPrice+'</td>';
	        		str += '	<td class="text-center">'+list[i].statusString+'</td>';
	        		str += '	<td class="text-center">'+list[i].refundReason+'</td>';
	        		str += '	<td class="text-center">'+list[i].paymark+'</td>';
	        		str += '	<td class="text-center">';
                    str += '		<a class="btn btn-default btn-delete" href="#" onclick=modify("'+list[i].id+'","'+list[i].realPrice+'")>修改金额</a>';
	        		if(list[i].status=="1"){
	        			str += '	<button class="btn btn-default " onclick=toUpdate('+list[i].id+')>同意</button>';
	        		}else if(list[i].status=="2"){
	        			str += '	<button class="btn btn-default " onclick=toUpdate('+list[i].id+')>确认收货</button>';
	        		}else if(list[i].status=="3"){
	        			str += '	<button class="btn btn-default " onclick=toUpdate('+list[i].id+')>打款</button>';
	        		}else if(list[i].status=="4"){
	        			str += '退款成功';
	        		}else if(list[i].status=="5"){
	        			str += '退款关闭';
	        		}else if(list[i].status=="6"){
	        			str += '退款取消';
	        		}
	        		str += '	</td>';
					str += '</tr>';
	        	}
	        	$("#orderProductRefundList").append(str);
	        	
	        	$("#pagination").empty();
	        	var pageString = "";
	        	var currentPage = page;
	        	var sumPage = Math.ceil(count/pageSize);
	        	pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage-1)+') aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>';
	        	for(var i=1;i<=sumPage;i++){
	        		if(currentPage == i){
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+') class="active">'+i+'</a></li>';
        			}else{
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+')>'+i+'</a></li>';
        			}
	        	}
	        	if(sumPage==currentPage){
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}else{
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage+1)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}
	        	
	        	$("#pagination").append(pageString);
	        }
	    })
	}

    var productIdCurrent = "";

    function modify(id,realPrice) {
        $('#modifyModel').modal();
        productIdCurrent = id;
        $("#realPrice").val(realPrice);
    }

    var pro_modify = function () {

        var type = "${type}";
        if(type == "3"){
            alert("当前账号无权限使用此功能");
            return;
        }

        var baseURL = "${webPath}/orderProductRefund/modifyRealPrice";
        var realPrice = $("#realPrice").val();
        var json_package = {
            "head": {},
            "body": {
                "id": productIdCurrent,
                "realPrice": realPrice
            }
        }
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('修改成功')
                window.location.reload(true);
            } else {
                alert(result.body.description)
            }
        })
    }

     function toUpdate(id){
    	var baseURL = "${webPath}/orderProductRefund/toupdate";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"id": id
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            alert(result.body.description);
	        } else {
	        	window.location.reload(true);
	        }
	    })
    }
    
</script>
</body>
</html>
